import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/',
    name: 'index',
    component: () => import('../views/index.vue'),
	children:[
		{
			path:'/',
			name:'home',
			component:() => import('../views/home'),
			children:[
				{
					path:'/underHome',
					name:'underHome',
					component:() => import('../views/underHome')
				},
				{
					path:'/photo',
					name:'photo',
					component:() => import('../views/photo')
				},
				{
					path:'/shopList',
					name:'shopList',
					component:() => import('../views/shopList')
				}
			]
		},
		{
			path:'commodity',
			name:'commodity',
			component:() => import('../views/commodity'),
			children:[
				{
					path:'/Listshop',
					name:'Listshop',
					component:() => import('../views/Listshop')
				},
				{
					path:'/商品-分类',
					name:'商品-分类',
					component:() => import('../views/商品-分类')
				},
				{
					path:'/商品-规格',
					name:'商品-规格',
					component:() => import('../views/商品-规格')
				},
				{
					path:'/商品-类型',
					name:'商品-类型',
					component:() => import('../views/商品-类型')
				},
				{
					path:'/商品-评论',
					name:'商品-评论',
					component:() => import('../views/商品-评论')
				},
			]
		},
		{
			path:'orderForm',
			name:'orderForm',
			component:() => import('../views/orderForm'),
			children:[
				{
					path:'/订单-发票',
					name:'订单-发票',
					component:() => import('../views/订单-发票')
				},
				{
					path:'/订单-管理',
					name:'订单-管理',
					component:() => import('../views/订单-管理')
				},
				{
					path:'/订单-售后',
					name:'订单-售后',
					component:() => import('../views/订单-售后')
				}
			]
		},
		{
			path:'vip',
			name:'vip',
			component:() => import('../views/vip'),
			children:[
				{
					path:'/会员-列表',
					name:'会员-列表',
					component:() => import('../views/会员-列表')
				},
				{
					path:'/会员-等级',
					name:'会员-等级',
					component:() => import('../views/会员-等级')
				}
			]
		},
		{
			path:'setting',
			name:'setting',
			component:() => import('../views/setting'),
			children:[
				{
					path:'/设置-基础',
					name:'设置-基础',
					component:() => import('../views/设置-基础')
				},
				{
					path:'/设置-物流',
					name:'设置-物流',
					component:() => import('../views/设置-物流')
				},
				{
					path:'/设置-管理员',
					name:'设置-管理员',
					component:() => import('../views/设置-管理员')
				},
				{
					path:'/设置-交易',
					name:'设置-交易',
					component:() => import('../views/设置-交易')
				}
			]
		},
	],
	
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

var userLoginStatus = false;
router.beforeEach((to,from,next) => {
	var userLoginStatus = localStorage.getItem("token");
	if(to.name === "Login"){
		next()
	} else {
		if(userLoginStatus){
			next()
		} else {
			next('/Login')
		}
	}
})

export default router
